/**
 * Created by Administrator on 2016/9/27.
 */
var Httpservice = '/pad_marketing/zy/json/GetOccupations.json';
//window.padMarketing.ajaxNormal(Httpservice,'', function (data) {
$.getJSON(Httpservice, function(data){	
	var typeNameMap = [];
	for(var i=0;i<data.Types.length;i++){
		var occ = [];
		for(var j=0;j<data.Occupations.length;j++){
			if(data.Occupations[j].type===data.Types[i].type){
				occ.push(data.Occupations[j]);
			}
		}
		typeNameMap[data.Types[i].type+"_"+data.Types[i].category] = occ;
	}
	var cateTypeMap = [];
	for(var i=0;i<data.Categories.length;i++){
		var types = [];
		for(var key1 in typeNameMap){
			if(key1.split('_')[1] == data.Categories[i].category){
				types[key1.split('_')[0]] = typeNameMap[key1];
			}
		}
		cateTypeMap[data.Categories[i].category] = types;
	}
	var html = '';
	for(var key2 in cateTypeMap){
		html += '<li>';
		html += '<span>'+key2+'</span>';
		html += '<ul>';
		var arr1 = cateTypeMap[key2];
		for(var key3 in arr1){
			html += '<li>'+key3;
			var arr2 = arr1[key3];
			for(var i=0;i<arr2.length;i++){
				html += '<ul>';
				html += '<li data-obj=\''+JSON.stringify(arr2[i])+'\'>';
				var str = arr2[i].name;
				str = str.split('/')[2];
				html += str;
				html += '</li>';
				html += '</ul>';
			}
			html += '</li>';
		}
		html += '</ul>';
		html += '</li>';
	}
	$('.works').html(html);
	//职业滑动控件
	var i = Math.floor($('.works>li').length / 2),
	j = Math.floor($('.works>li').eq(i).find('ul li').length / 2),
	k = Math.floor($('.works>li').eq(i).find('ul li').length / 2);
	$(".works").mobiscroll().treelist({
		theme: "android-ics light",
		lang: "zh",
		display: 'modal',
		defaultValue: [i,j,k],
		setText: '确定',
		cancelText: '取消',
		placeholder: '职业选择',
		headerText: function (valueText) { return ""; },
		formatResult: function (array) { //返回自定义格式结果
			$('.works>li').eq(array[0]);
			var str = $('.works>li').eq(array[0]).children('span').text();
			var str2 = $('.works>li').eq(array[0]).children('ul').children('li:eq('+array[1]+')').html();
			if(str2){
				str2 = str2.split('<')[0];
			}
			var str3=$('.works>li').eq(array[0]).children('ul').children('li:eq('+array[1]+')').find('ul li').eq(array[2]).text();
			
			return str3;
		},
		onClose:function(valueText, btn, inst){
			var array = inst.temp;
			//将选中的值赋值到外部input框中
			var curLi = $(this).find('>li').eq(array[0]).children('ul').children('li:eq('+array[1]+')').find('ul li').eq(array[2]);
			curLi.closest('input').prev('input').data('selected',curLi.data('obj'));
		},
	});

	/*popDate();*/
});
//},'',false)

